package com.battleship;

import java.util.ArrayList;
import java.util.List;

public class Game2 implements Game {

    private List<Ship> shipList;
    private List<Point> guesses;

    public Game2() {
        guesses = new ArrayList<>();

        shipList = new ArrayList<>();
        shipList.add(new Ship("dingy", new Point(1,2), new Point(1,3)));
        shipList.add(new Ship("submarine", new Point(3,10), new Point(4,10), new Point(5,10)));
        shipList.add(new Ship("destroyer", new Point(1,6), new Point(1,7), new Point(1,8)));
        shipList.add(new Ship("battleship", new Point(3,9), new Point(4,9), new Point(5,9), new Point(6,9)));
        shipList.add(new Ship("carrier", new Point(10,4), new Point(10,5), new Point(10,6), new Point(10,7), new Point(10,8)));
    }

    @Override
    public int guess(Point point) {
        if (guesses.contains(point)) {
            return -1;
        }

        guesses.add(point);

        for (Ship ship : shipList) {
            int check = ship.guess(point);
            if (check > 0) {
                if (check == 2) {
                    shipList.remove(ship);
                }

                return check;
            }
        }

        return 0;
    }

    @Override
    public int getShipsLeft() {
        return shipList.size();
    }

    @Override
    public int getGuessCount() {
        return guesses.size();
    }
}
